#include <stdlib.h>
#include <stdio.h>
#include "lsg_buddybit.h"
#include "lsg_log.h"

using namespace LSG;

int main(int argc, char * argv[])
{
    if (argc != 2)
    {
	printf("test_buddybit buddybit_total\n");
	return -1;
    }

    lsg_set_log_path("./log");

    int buddybit_total = atoi(argv[1]);
    int bytes = buddybit_total * 2 / 8;

    CBuddyBit buddybit(NULL, bytes);

    int i, j, buddybit_offset;

    printf("alloc %d blocks...\n\n", buddybit_total / 4 + 1);
    buddybit_offset = buddybit.Alloc(buddybit_total / 4 + 1, &i, &j);
    buddybit.PrintInfo();

    printf("\nalloc %d blocks...\n\n", buddybit_total / 4);
    buddybit_offset = buddybit.Alloc(buddybit_total / 4, &i, &j);
    buddybit.PrintInfo();

    printf("\nfree %d blocks...\n\n", buddybit.SlotItemSize(buddybit_offset));
    buddybit.Free(buddybit_offset, &i, &j);
    buddybit.PrintInfo();

    return 0;
}
